﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SquareChaseBot
{
    /// <summary>
    /// Mouse API functions.
    /// </summary>
    internal static class Mouse
    {
        #region Methods

        /// <summary>
        /// Left clicks the mouse at the current position.
        /// </summary>
        internal static void LeftClick()
        {
            mouse_event((int)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
            mouse_event((int)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
        }

        /// <summary>
        /// The mouse_event function synthesizes mouse motion and button
        /// clicks.
        /// </summary>
        /// <param name="dwFlags">
        /// Controls various aspects of mouse motion and button clicking. This 
        /// parameter can be certain combinations of the following values (see
        /// ref #1).
        /// </param>
        /// <param name="dx">
        /// The mouse's absolute position along the x-axis or its amount of 
        /// motion since the last mouse event was generated, depending on the 
        /// setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the 
        /// mouse's actual x-coordinate; relative data is specified as the 
        /// number of mickeys moved. A mickey is the amount that a mouse has to
        /// move for it to report that it has moved. 
        /// </param>
        /// <param name="dy">
        /// The mouse's absolute position along the y-axis or its amount of 
        /// motion since the last mouse event was generated, depending on the 
        /// setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the 
        /// mouse's actual y-coordinate; relative data is specified as the 
        /// number of mickeys moved. 
        /// </param>
        /// <param name="dwData">
        /// <para>
        /// If dwFlags contains MOUSEEVENTF_WHEEL, then dwData specifies the 
        /// amount of wheel movement. A positive value indicates that the wheel 
        /// was rotated forward, away from the user; a negative value indicates 
        /// that the wheel was rotated backward, toward the user. One wheel 
        /// click is defined as WHEEL_DELTA, which is 120.
        /// </para>
        /// <para>
        /// If dwFlags contains MOUSEEVENTF_HWHEEL, then dwData specifies the 
        /// amount of wheel movement. A positive value indicates that the wheel 
        /// was tilted to the right; a negative value indicates that the wheel 
        /// was tilted to the left.
        /// </para>
        /// <para>
        /// If dwFlags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then 
        /// dwData specifies which X buttons were pressed or released. This 
        /// value may be any combination of the following flags.
        /// </para>
        /// <para>If dwFlags is not MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or 
        /// MOUSEEVENTF_XUP, then dwData should be zero.
        /// </para>
        /// </param>
        /// <param name="dwExtraInfo">
        /// An additional value associated with the mouse event. An application
        /// calls GetMessageExtraInfo to obtain this extra information. 
        /// </param>
        /// <remarks>
        /// Ref (1): http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260%28v=vs.85%29.aspx
        /// Ref (2): http://www.pinvoke.net/default.aspx/user32.mouse_event
        /// </remarks>
        [DllImport("user32.dll")]
        internal static extern void mouse_event(uint dwFlags, uint dx, uint dy, 
            uint dwData, int dwExtraInfo);

        /// <summary>
        /// Right clicks the mouse at the current position.
        /// </summary>
        internal static void ReftClick()
        {
            mouse_event((int)MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0);
            mouse_event((int)MouseEventFlags.RIGHTUP, 0, 0, 0, 0);
        }

        #endregion
    }
}
